<template>
  <div class="header">
    <div class="headerTop">
      <div class="left">
        <span>欢迎来到四川省大学生学科竞赛平台</span>
        <!-- <a
          href="javascript:void(0)"
          v-if="!userInfo"
          @click="$router.push('/login')"
          >登录/注册</a
        >
        <a href="javascript:void(0)" @click="toPerson" v-else
          >欢迎：{{ userInfo.userName }}</a
        > -->
      </div>
      <div v-if="userInfo" class="right">
        <span style="margin-right: 10px" @click="logout">退出</span>
        <span>{{ userInfo.userName }}</span>
        <span @click="$router.push('/userCenter')">用户中心</span>
      </div>
    </div>
    <div class="headerWrap">
      <div class="left-img">
        <img
          width="400px"
          height="50px"
          src="@/assets/img/system_icon.png"
          alt=""
        />
      </div>
      <div class="mainNav">
        <ul>
          <li>
            <a href="javascript:void(0);" @click="$router.push('/')">首页</a>
          </li>
          <li>
            <a href="javascript:void(0);">通知公告</a>
          </li>
          <li>
            <a href="javascript:void(0);">新闻资讯</a>
          </li>
          <li>
            <a href="javascript:void(0);">赛项信息</a>
          </li>
        </ul>
      </div>
      <div class="searchArea row center">
        <el-input
          v-model="input"
          size="small"
          placeholder="请输入关键字"
        ></el-input>
      </div>
      <!-- 绝对定位布局的电话卡片 -->
      <div
        @mouseenter="toNavTel"
        @mouseleave="toNavTel"
        class="nav-tel row"
        :class="{ 'nav-tel-active': nav_tel }"
      >
        <ul class="nav-tel-list">
          <li>境内：95010</li>
          <li>（或）400-830-6666</li>
          <li v-if="nav_tel">香港(中国)：+852-3069-9966</li>
          <li v-if="nav_tel">境外：+86-21-3406-4888</li>
        </ul>
        <i v-if="!nav_tel" class="el-icon-caret-bottom arrow color999"></i>
        <i v-else class="el-icon-caret-top arrow color999"></i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "indexHeader",
  data() {
    return {
      // 电话卡片的显示
      nav_tel: false,
      input: "",
    };
  },
  mounted() {
    // console.log("获取用户信息", this.userInfo);
  },
  computed: {
    userInfo() {
      return JSON.parse(localStorage.getItem("userInfo"));
    },
  },
  methods: {
    showSub(index) {
      if (this.tabData[index].sub.length != 0) {
        this.tabData[index].isShow = true;
      }
    },
    hideSub(index) {
      if (this.tabData[index].sub.length != 0) {
        this.tabData[index].isShow = false;
      }
    },
    toNavTel() {
      this.nav_tel = !this.nav_tel;
    },
    toPerson() {
      this.$router.push("/person");
    },
    logout() {
      this.$confirm("此操作将退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          localStorage.removeItem("userInfo");
          this.$router.push("/");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    }
  },
};
</script>

<style scoped>
.header {
  display: flex;
  flex-direction: column;
  text-align: center;
  z-index: 10;
}
a {
  text-decoration: none;
  color: #666;
}
a:hover {
  color: #2577e3;
}
.mainNav ul {
  padding-left: 0px;
}
.mainNav ul li {
  font-size: 16px;
  line-height: 28px;
  background: url(http://scsbk.ycfuture.cn/templates/system/green/img/icon001.png)
    no-repeat left center;
  padding: 5px 20px 5px 25px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  cursor: pointer;
  color: #404040;
}
.headerTop {
  height: 35px;
  line-height: 35px;
  font-size: 13px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  border-bottom: 1px solid green;
  color: #9dcff3;
  padding: 0 320px;
  z-index: 10;
  background-color: green;
}
.headerTop .left {
  display: flex;
  flex-direction: row;
}
.headerTop .right {
  display: flex;
  flex-direction: row;
}
.headerTop .right span {
  margin-left: 25px;
  cursor: pointer;
}
.headerWrap {
  padding: 0 320px;
  background-color: green;
  height: 120px;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.headerWrap .left-img {
  float: left;
  cursor: pointer;
  display: flex;
}
.headerWrap .nav-tel {
  float: right;
  padding: 0px 5px 0px 0px;
  text-align: right;
  /* margin-top: 10px; */
  position: absolute;
  top: 60px;
  right: 50px;
}
.headerWrap .nav-tel .nav-tel-list {
  text-align: right;
  color: #fff;
  font-size: 12px;
  line-height: 20px;
}
.headerWrap .nav-tel-active {
  color: #333;
  background-color: green;
  padding: 0px 5px 10px 0px;
  border: 1px solid green;
  box-shadow: 0px 6px 8px 0px rgb(0 0 0 / 15%);
}
.headerWrap .nav-tel .arrow {
  margin-top: 25px;
}
.mainNav ul {
  vertical-align: baseline;
  color: #fff;
}
.mainNav a {
  line-height: 30px;
  color: #ffffff;
  padding: 0px 18px;
  font-size: 16px;
  cursor: pointer;
}
.mainNav ul li {
  float: left;
  background: url(http://scsbk.ycfuture.cn/templates/system/green/img/mainNav-icon.png)
    no-repeat left center;
  padding-left: 5px;
}
</style>